package utils;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class InputReader {

	/**
	 * Reads a list of vectors from an input file and returns a list of corresponding DegreeVector objects.
	 * @param fileName The name of the input file.
	 * @param delimiter Delimiter used to separate vector entries in the input file (default is comma).
	 * @return A list of corresponding DegreeVector objects.
	 */
	public List<DegreeVector> readInputFromFile(String fileName, String delimiter) {
		List<DegreeVector> results = new ArrayList<DegreeVector>();
		File file = new File(fileName);
		Scanner scan = null; 
		try {
			scan = new Scanner(file);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		while(scan.hasNextLine()) {
			String[] line = scan.nextLine().split(delimiter);
			Double[] values = new Double[line.length];
			int i = 0;
			for(String s : line) {
				Double entry = Double.parseDouble(s);
				values[i++] = entry;
			}
			results.add(new DegreeVector(values));
		}
		return results;
	}
}
